package com.fengzhi.crawler.jsoup.queue;

import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;

public class LinkQueue {

	// 已访问地址
	private static Set<String> visitedUrl = new HashSet<String>();;

	// 未访问地址
	private static Queue<String> unVisitedUrl = new PriorityQueue<String>();

	/**
	 * 
	 * @Title: addVisitedUrl
	 * @Description: TODO(添加已访问url)
	 * @author fyf
	 * @param url
	 */
	public static void addVisitedUrl(String url) {
		visitedUrl.add(url);
	}

	/**
	 * 
	 * @Title: removedVisitedUrl
	 * @Description: TODO(删除已访问url)
	 * @author fyf
	 * @param url
	 */
	public static void removedVisitedUrl(String url) {
		visitedUrl.remove(url);
	}

	/**
	 * 
	 * @Title: getVisitedUrl
	 * @Description: TODO(获取已访问url集合)
	 * @author fyf
	 * @return
	 */
	public static Set<String> getVisitedUrl() {
		return visitedUrl;
	}

	/**
	 * 
	 * @Title: getVisitedUrlSize
	 * @Description: TODO(已访问url数量)
	 * @author fyf
	 * @return
	 */
	public static int getVisitedUrlSize() {
		return visitedUrl.size();
	}

	/**
	 * 
	 * @Title: pollQueue
	 * @Description: TODO(检索取出未访问url，并从队列中删除)
	 * @author fyf
	 * @return url
	 */
	public static String unVisitedUrlDeQueue() {
		return unVisitedUrl.poll();
	}

	/**
	 * 
	 * @Title: addUnVisitedUrl
	 * @Description: TODO(添加未访问url)
	 * @author fyf
	 * @param url
	 */
	public static void addUnVisitedUrl(String url) {
		if (url != null && !"".equals(url.trim()) && !visitedUrl.contains(url) && !unVisitedUrl.contains(url)) {
			unVisitedUrl.add(url);
		}
	}

	/**
	 * 
	 * @Title: unVisitedUrlIsEmpty
	 * @Description: TODO(判断未访问url队列是否为空)
	 * @author fyf
	 * @return
	 */
	public static boolean unVisitedUrlIsEmpty() {
		return unVisitedUrl.isEmpty();
	}

	public static int getUnVisitedUrlSize() {
		return unVisitedUrl.size();
	}

}
